package com.wifi.user.servlet;

import com.alibaba.fastjson.JSON;
import com.wifi.unti.PageInfo;
import com.wifi.user.service.MenuService;
import com.wifi.user.service.MenuServiceImpl;
import org.w3c.dom.ls.LSOutput;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/menu")
public class MenuServlet extends HttpServlet {
    MenuService menuService=new MenuServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("WEB-INF/user/menuMana.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String pageNum=request.getParameter("pageNum");
        String pageSize=request.getParameter("pageSize");
        String pid=request.getParameter("fatherid");
//        String cloumn=request.getParameter("cloumn");
//        String order=request.getParameter("order");

//        System.out.println(pageNum);
//        System.out.println(pageSize);
//        System.out.println(pid);
//        System.out.println(cloumn);
//        System.out.println(order);
        long totalNum = menuService.selectCount(pid);

        PageInfo pageInfo = new PageInfo(pageNum,pageSize,(int)totalNum );

List<Object> menuPage=menuService.getMenuPage(pageInfo.getStart(),pageInfo.getPageSize(),pid);
        pageInfo.setList(menuPage);
        System.out.println(JSON.toJSONString(pageInfo));
        response.getWriter().write(JSON.toJSONString(pageInfo));
    }
}


